

var dateTimePicker = require('../../utils/dateTimePicker.js');
import {request} from "../../request/index.js"



Page({
  data: {
    list: [],
    show: false,
    show2: false,
    show3: false,
    text: '',
    text2: '',
    text3: '',
    one: [],
    num: '',
    line: '',
    userName: '',
    lineList1: [],
    lineList2: [],
    lineList3: [],
    busBar: '',
    superior: '',
    click: false,
    click1: false,
    click2: false,
    updateShow:false,//控制下拉列表的显示隐藏，false隐藏、true显示
    selectData:['准备抢修', '开始检修', '结束检修', '开始供电'],//下拉列表的数据
    index:0,//选择的下拉列表下标
    schedule: '准备检修',
    id: ''
    },
  onLoad(options){
    console.log(options)
    
    request({
      url: '/client/get/fault/one/by/' + options.id,
      data: {

      }
    })
    .then(res => {
      console.log(res)
      this.setData({
        list: res.data,
        userName: res.data.name
      })
    })
    
    this.setData({
      text: options.text,
      text2: options.text2,
      text3: options.text3,
      id: options.id,
      busBar: options.line1,
      superior: options.line2,
      line: options.line3,
    });

    

    this.setData({
    })
    
  },
  onShow() {
    request({
      url: '/api/list/line/tree',
      data: {
      },
      header: {

      }
    })
    .then(res => {
      var primaryList = res.data.data
      var primary = []
      var onePrimary = []
      primaryList.forEach((item, i) => {
        primary.push(item)
      })
      this.setData({
        one: primary
      })
    })


    
  },
 
  bindShowMsg() {
    this.setData({
      show: !this.data.show,
      text2: '请选择出线',
      text3: '请选择出线',
      lineList3: [],
      lineList2: []
    })

    request({
      url: "/api/list/busbar",
      data: {}
    })
    .then(res => {
      this.setData({
        lineList1: res.data.data
      })
    })

  },
  bindShowMsg2() {
    this.setData({
      show2: !this.data.show2,
      text3: '请选择出线',
      lineList3: []
    })
  },
  bindShowMsg3() {
    this.setData({
      show3: !this.data.show3
    })
  },
  selectItem(e) {
    var busBar = e.currentTarget.dataset.name
    this.setData({
      busBar
    })
    if (busBar.length == 0 || busBar == undefined) {
      return false;
    } else {
      request({
        url: "/api/list/superior/?busBar=" + busBar,
        data: {

        }
      })
      .then(res => {
        this.setData({
          lineList2: res.data.data
        })
      })
      if(busBar.length > 6) {
        busBar = busBar.substring(0,6) + "...";
        this.setData({
          text: busBar,
          show: false
        })
      } else {
        this.setData({
          text: busBar,
          show: false
        })
      }  
    } 
    
    
  },
  selectItem2(e) {
    var superior = e.currentTarget.dataset.name
    this.setData({
      superior
    })
    if (superior.length == 0 || superior == undefined) {
      return false;
    } else {
      request({
        url: "/api/list/belong/?superior=" + superior,
        data: {

        }
      })
      .then(res => {
        var data = res.data.data
        
        this.setData({
          lineList3: data
        })
      })

      if(superior.length > 6) {
        superior = superior.substring(0,6) + "...";
        this.setData({
          text2: superior,
          show2: false
        })
      } else {
        this.setData({
          text2: superior,
          show2: false
        })
      }
    }
  },
  selectItem3(e) {
    var name = e.currentTarget.dataset.name
    this.setData({
      line: name
    })
    if (name.length == 0 || name == undefined) {
      return false;
    } else if(name.length > 6) {
      name = name.substring(0,6) + "...";
      this.setData({
        text3: name,
        show3: false
      })
    } else {
      this.setData({
        text3: name,
        show3: false
      })
    }
  },
  getName(e) {

    this.setData({
      userName: e.detail.value
    }) 
  },
  // 点击下拉显示框
  selectTap(){
    this.setData({
     updateShow: !this.data.updateShow
    });
  },
  // 点击下拉列表
  optionTap(e){
    
    let Index=e.currentTarget.dataset.index;//获取点击的下拉列表的下标
    
    var schedule = ''
    this.data.selectData.forEach((v,i) => {
      if(i === Index) {
        schedule = v
      }
    })

    this.setData({
      index:Index,
      updateShow:!this.data.updateShow,
      schedule
    })
    
  },
  update() {
    wx.chooseLocation({
      latitude: 0,
    })

    // request({
    //   url: '/api/change/overhaul',
    //   method: 'PUT',
    //   data: {
    //     endTime: this.data.list.endTime,
    //     line: this.data.line,
    //     name: this.data.userName,
    //     startTime: this.data.list.startTime,
    //     stationAndBusbar: this.data.busBar,
    //     superior35kv: this.data.superior,
    //     id: this.data.id,
    //     schedule: this.data.schedule,
    //     reason: this.data.list.reason
    //   },
    //   header: {
    //     'content-type': 'application/x-www-form-urlencoded'
    //   }
    // })
    // .then(res => {
    //   if(res.data.code === 500) {
    //     wx.showToast({
    //       title: res.data.message,
    //       mask: true,
    //       icon: 'none'
    //     })
    //   } else {
    //     wx.navigateBack({
    //       delta: 2,
    //     })
    //   }
    // })
    
  }
})